package com.jhws.business.property.bo;

import com.jhws.business.owner.bo.TblOwnerDimBo;
import com.jhws.business.owner.service.ITblOwnerDimService;
import com.jhws.business.property.service.PropertyFeeService;
import com.jhws.core.dataUpdate.bo.DataUpdateObject;
import com.jhws.core.dataUpdate.bo.IDataUpdateModule;
import com.jhws.core.dataUpdate.service.DataUpdateService;
import com.jhws.core.exception.BizException;
import com.jhws.util.LogHelper;
import com.jhws.util.StringUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

@Component
public class PropertyFeeDataUpdate implements IDataUpdateModule {
    static public String PROPERTY_FEE = "PropertyFee";
    private String[] name = {PROPERTY_FEE};
    @Resource
    private DataUpdateService dataUpdateService;
    @Resource
    private PropertyFeeService propertyFeeService;
    @Resource
    private ITblOwnerDimService ownerService;
    @Override
    public String[] getModuleName() {
        return name;
    }

    @Override
    public DataUpdateObject getUserModuleData(String username, String ownerCode,Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {

        if (timeStamp == null || StringUtils.isEmpty(ownerCode)) {
            LogHelper.e("参数错误");
            return null;
        }
        TblOwnerDimBo owner = ownerService.findTblOwnerDimById(ownerCode);

        PropertyFeeInfo propertyFeeInfo = propertyFeeService.queryPropertyFee(owner.getRoomInfoNum());
        if (propertyFeeInfo !=null && propertyFeeInfo.getIsPay() == 0) {
            return new DataUpdateObject(null, 1);
        }
        return new DataUpdateObject(null);
    }

    @Override
    public DataUpdateObject getLabelModuleData(String label, Long timeStamp, String module, Map<String, String> moduleParams) throws Exception {
        return null;
    }

    @Override
    @PostConstruct
    public void registerModule() {
        dataUpdateService.registerModule(this);
    }
}
